﻿namespace Alkitab
{
    using System;
    using System.Runtime.Serialization;

    [DataContractAttribute]
    public class AyatFull : IComparable
    {
        #region Fields

        [DataMember]
        public String isiAyat;

        [DataMember]
        public int noAyat;

        [DataMember]
        public int noBuku;

        [DataMember]
        public int noPasal;

        [DataMember]
        public Boolean terjemahanLama;

        #endregion Fields

        #region Constructors

        public AyatFull(Boolean terjemahanLama, int noBuku, int noPasal, int noAyat, String isiAyat)
        {
            this.terjemahanLama = terjemahanLama;
            this.noBuku = noBuku;
            this.noPasal = noPasal;
            this.noAyat = noAyat;
            this.isiAyat = isiAyat;
        }

        #endregion Constructors

        #region Properties

        public String ayatFullText
        {
            get
            {
                return getKitabName() + " " + this.noPasal + "\n" + this.isiAyat + "\n";
            }
        }

        #endregion Properties

        #region Methods

        public int CompareTo(object obj)
        {
            if (obj == null) return 1;

            AyatFull ayatFullLain = obj as AyatFull;
            if (ayatFullLain != null)
            {
                if (this.terjemahanLama && (!ayatFullLain.terjemahanLama)) return -1;
                if ((!this.terjemahanLama) && ayatFullLain.terjemahanLama) return 1;
                if (this.noBuku < ayatFullLain.noBuku) return -1;
                if (this.noBuku > ayatFullLain.noBuku) return 1;
                if (this.noPasal < ayatFullLain.noPasal) return -1;
                if (this.noPasal > ayatFullLain.noPasal) return 1;
                if (this.noAyat < ayatFullLain.noAyat) return -1;
                if (this.noAyat > ayatFullLain.noAyat) return 1;
                return 0;
            }
            else
            {
                throw new ArgumentException("Object is not an ayatFull");
            }
        }

        public String toString()
        {
            return isiAyat;
        }

        private string getKitabName()
        {
            if (this.terjemahanLama) return Globals.daftarBukuA[this.noBuku - 1];
            else
            {
                if (this.noBuku > 0) return Globals.daftarBukuN[this.noBuku - 1];
                else return Globals.daftarBukuN[this.noBuku];
            }
        }

        #endregion Methods
    }
}